const app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        weika:[
            'http://image.browin.net.cn/static/202251/img/weika01.jpg',
            'http://image.browin.net.cn/static/202251/img/weika02.jpg',
            'http://image.browin.net.cn/static/202251/img/weika03.jpg',
            'http://image.browin.net.cn/static/202251/img/weika04.jpg',
            'http://image.browin.net.cn/static/202251/img/weika05.jpg',
            'http://image.browin.net.cn/static/202251/img/weika06.jpg',
            'http://image.browin.net.cn/static/202251/img/weika07.jpg',
            'http://image.browin.net.cn/static/202251/img/weika08.jpg'
        ],
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        let that=this;
      
        var parent_id=options.parent_id;
        if(parent_id!=undefined){
            this.setData({
                parent_id:parent_id
              })
              wx.setStorageSync('parent_id',parent_id);
        }else{
            parent_id = wx.getStorageSync('parent_id');
        
        }
        var open=wx.getStorageSync('open');
        if(open==""){
            wx.navigateTo({
              url: '../login/index?parent_id='+parent_id,
            })
        }
        
        wx.showShareMenu({
            menus: ['shareAppMessage', 'shareTimeline'],
            success(res) {
              console.log(res)
            },
            fail(e) {
              console.log(e)
            }
          })  
                  
        that.setData({
            platform:app.globalData.platform,    
            open:open,
            width:app.globalData.windowWidth,
            height:app.globalData.windowHeight,
            statusBarHeight:app.globalData.statusBarHeight,
            navHeight:app.globalData.navHeight,
            marginTop:app.globalData.navTitleTop,
            domain:app.globalData.platUrl,
            uploadUrl:app.globalData.uploadUrl,
          })
          this.getIndex();  
    },
    
 getIndex:function(){
    let that = this; 
    var open=this.data.open;      
    wx.request({
      url: app.globalData.platUrl+'model/getIndex',
      data:{from:1,user_id:open.user_id},
      success:res=>{
          console.log(res)
         if(res.statusCode==200){
             let data=res.data;
            that.setData({
             weika:data.weika,
             xiaoka:data.xiaoka,
             qingka:data.qingka,
             zhongka:data.zhongka,
             van:data.van,
             shareTitle:data.shareTitle,
             shareLogo:data.shareLogo,
             backgroud:data.backgroud
            })
         }
      }
    })
 },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },
goShopcart:function(){
    wx.navigateTo({
      url: '../shopcart/index',
    })
},
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },
    onShareTimeline(){
        //console.log(e);
        var title=this.data.shareTitle;
        var shareLogo=this.data.shareLogo;
        var open=wx.getStorageSync('open');

        var parent_id=open.user_id;
         this.setData({
           share:true
         });
         console.log(shareLogo);
         console.log(title);
         return{
           title: title,                 
           query: 'parent_id='+parent_id,        
           imageUrl:shareLogo      
           }
       },
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage(e) {
        var open=wx.getStorageSync('open');
        var parent_id=open.user_id;
        var that = this;
        var title=this.data.shareTitle;
        var shareLogo=this.data.shareLogo;
   　　var shareObj = {
   　　　　title: title,    
   　　　　path: '/pages/index/index?parent_id='+parent_id,   
   　　　　imageUrl: shareLogo 
   　　　
   　　}
   　　// 来自页面内的按钮的转发
   　　if( e.from == 'button' ){
     　　　shareObj.title=title;
   　　　　shareObj.path = '/pages/index/index?     parent_id='+parent_id;
   　　}
   console.log(shareObj);
   　　// 返回shareObj
   　　return shareObj;
    }
})